<?php
	$object=$_GET['object'];
	if($object=='nguoidung')
	{
		$user=$_SESSION['admin'];
		$kq=$knoi->queryCsdl("select a.makh,tenkh,tendn,mail,dienthoai,quyen from khachhang a,taikhoan b where a.makh=b.makh");
		if(mysql_num_rows($kq)<1)
		{
			echo "<br><label class='stylelitle'>Hiện tại hệ thống chưa có người dùng nào!</label><br>";
		}
		else
		{
?>
	<p class="styletitle" align="center">DANH SÁCH NGƯỜI DÙNG</p>
		<table align="center" style="border:solid #FFFFFF; background-color:#F5F5F5">
			<tr class="stylelitle" style="text-align:center; background-color:#CCFFFF"><td width="6%">Stt</td>
			<td>Tên đăng nhập</td>
			<td>Họ tên</td>
			<td>Điện thoại</td>
			<td>Email</td>
			<td>Quyền</td>
			<td>Chi tiết</td>
			<td>Xóa</td>
			</tr>
			<?php
			$i=1;
			if(isset($_GET['i']))
				$i=$_GET['i'] + 1;
			while($n=mysql_fetch_array($kq))
			{
				$module='thongtinnguoidung';
				if($i%2==0)
					$color='#FFFFCC';
				else
					$color='#FFFFFF';
				if($n['tendn']==$user)
				{
					$module='thongtincanhan';
				}
		?>
					<tr style="background-color:<?php echo $color; ?>" class="classtr"><td align="right"><?php echo $i; ?>&nbsp;</td><td>&nbsp;<?php echo $n['tendn']; ?></td><td>&nbsp;<?php echo $n['tenkh']; ?></td><td>&nbsp;<?php echo $n['dienthoai']; ?></td><td>&nbsp;<?php echo $n['mail']; ?></td><td>&nbsp;<?php if($n['quyen']==1) echo 'Quản trị'; else echo 'Không'; ?></td><td style="text-align:center"><a href="home_admin.php?module=<?php echo $module; ?>&makh=<?php echo $n['makh']; ?>"><img src="images/chitiet.png" border="0" title="Thông tin chi tiết" /></a></td><td style="text-align:center">
					<?php
						if($module=='thongtincanhan')
						{
					?>
					<img src="images/Sign-Error-icon1.png" border="0" title="Không được xóa" />
					<?php
						}
						else
						{
					?>
							<a href="home_admin.php?module=xoa&field=makh&table=khachhang&value=<?php echo $n['makh']; ?>&object=nguoidung"><img src="images/Sign-Error-icon1.png" border="0" title="Xóa người dùng" /></a>
					<?php
						}
					?>
					</td></tr>
			<?php
				$i++;	
				}
			?>
		</table>
<?php
		}
	?>
		<br /><label style="text-align:center" class="button"><a href="home_admin.php?module=themnguoidung"><img src="images/add.png" border="0">&nbsp;Người dùng mới</a></label>
	<?php
	}
	else
	{
		$kq=$knoi->queryCsdl("select makh,tenkh,mail,dienthoai from khachhang where makh not in (select makh from taikhoan)");
		if(mysql_num_rows($kq)<1)
		{
			echo "<br><label class='stylelitle'>Hiện tại hệ thống chưa có khách hàng!</label><br>";
		}
		else
		{
		$tongdong=mysql_num_rows($kq);
		$dong_trang=9;
		$sotrang=ceil($tongdong/$dong_trang);
		
		$limit="0,".$dong_trang;
		if(isset($_GET['page']))
		{
			$t=$_GET['page'];
			$ar=explode(":",$t);
			$limit=$ar[1];
		}
		if($sotrang>1)
			$kq=$knoi->queryCsdl("select makh,tenkh,mail,dienthoai from khachhang where makh not in (select makh from taikhoan) limit $limit");
				?>
	<p class="styletitle" align="center">DANH SÁCH KHÁCH HÀNG</p>
		<table align="center" style="border:solid #FFFFFF; background-color:#F5F5F5">
			<tr class="stylelitle" style="text-align:center; background-color:#CCFFFF"><td width="6%">Stt</td>
			<td>MAKH</td>
			<td>Họ tên</td>
			<td>Điện thoại</td>
			<td>Email</td>
			<td>Chi tiết</td>
			<td>Xóa</td>
			</tr>
			<?php
				$i=1;
				while($n=mysql_fetch_array($kq))
				{
					if($i%2==0)
						$color='#FFFFCC';
					else
						$color='#FFFFFF';
			?>	
					<tr style="background-color:<?php echo $color; ?>" class="classtr"><td align="right"><?php echo $i; ?>&nbsp;</td><td>&nbsp;<?php echo $n['makh']; ?></td><td>&nbsp;<?php echo $n['tenkh']; ?></td><td>&nbsp;<?php echo $n['dienthoai']; ?></td><td>&nbsp;<?php echo $n['mail']; ?></td><td align="center"><a href="home_admin.php?module=thongtinkhachhang&makh=<?php echo $n['makh']; ?>"><img src="images/chitiet.png" border="0" title="Thông tin chi tiết" /></a></td><td align="center"><a href="home_admin.php?module=xoa&field=makh&table=khachhang&value=<?php echo $n['makh']; ?>"><img src="images/Sign-Error-icon1.png" border="0" title="Xóa khách hàng" /></a></td></tr>
			<?php
				$i++;	
				}
			?>
		</table>
<?php
		if($sotrang>1)
			{
		 	if($ar[0]!=1 && isset($_GET['page']))
				$color='#0033CC';
			else
				$color='#000000';
			$start="1:0,".$dong_trang;
			?>
			<div> Pages &nbsp;
			<?php
				echo "<a href='home_admin.php?module=danhsachnguoidung&page=$start' style='color:$color'>1</a>";
			for($i=2;$i<=$sotrang;$i++)
			{
				if($ar[0]==$i)
					$color='#000000';
				else
					$color='#0033CC';
				$p=($i-1)*$dong_trang;
				$page=$i.":".$p.",".$dong_trang;
				echo "&nbsp;<a href='home_admin.php?module=danhsachnguoidung&page=$page&i=$p' style='color:$color'>$i</a>";	
			}
		}
		}
		if($c<1)
			echo "<br>";
	?>
		<br /><label style="text-align:center" class="button"><a href="home_admin.php?module=themmoikhachhang"><img src="images/add.png" border="0">&nbsp;Khách hàng mới</a></label>
	<?php
	}
?>